using System;
using System.IO;
using System.IO.Compression;
using System.Text;
using System.Text.RegularExpressions;
public class GzipUtil
{
	public static Random random = new Random();
	public static string regex_str = "<[^>]*>";
	public static string randStr(int count)
	{
		string text = "";
		for (int i = 0; i < count; i++)
		{
			if (GzipUtil.random.Next(0, 2) == 0)
			{
				text += (char)GzipUtil.random.Next(65, 91);
			}
			else
			{
				text += (char)GzipUtil.random.Next(97, 123);
			}
		}
		return text;
	}
	public static string html_to_text(string content)
	{
		return Regex.Replace(content, GzipUtil.regex_str, "");
	}
	public static string zip_to_string(byte[] byte_0, Encoding encoding)
	{
		MemoryStream stream = new MemoryStream(byte_0);
		MemoryStream memoryStream = new MemoryStream();
		GZipStream gZipStream = new GZipStream(stream, CompressionMode.Decompress);
		byte[] array = new byte[1000];
		int count;
		while ((count = gZipStream.Read(array, 0, array.Length)) > 0)
		{
			memoryStream.Write(array, 0, count);
		}
		byte_0 = memoryStream.ToArray();
		return encoding.GetString(byte_0);
	}
	public static byte[] zip_to_byte(string content, Encoding encoding_0)
	{
		byte[] bytes = encoding_0.GetBytes(content);
		MemoryStream memoryStream = new MemoryStream();
		GZipStream gZipStream = new GZipStream(memoryStream, CompressionMode.Compress, true);
		gZipStream.Write(bytes, 0, bytes.Length);
		gZipStream.Close();
		return memoryStream.ToArray();
	}
	public static string smethod_4(string string_1)
	{
		string_1 = string_1.Replace("&nbsp;", "");
		while (string_1.Contains("&#"))
		{
			int num = string_1.IndexOf("&#") + 2;
			int length = string_1.IndexOf(";", num) - num;
			string text = string_1.Substring(num, length);
			string newValue = GzipUtil.unicode_to_str("\\u" + int.Parse(text).ToString("x8").Substring(4));
			string_1 = string_1.Replace("&#" + text + ";", newValue);
		}
		return string_1;
	}
	public static string unescape(string content)
	{
		StringBuilder stringBuilder = new StringBuilder();
		if (!string.IsNullOrEmpty(content))
		{
			string[] array = content.Split(new char[]
			{
				'%'
			});
			try
			{
				for (int i = 1; i < array.Length; i++)
				{
					int num = Convert.ToInt32(array[i], 16);
					stringBuilder.Append((char)num);
				}
			}
			catch (FormatException)
			{
				return Regex.Unescape(content);
			}
		}
		return stringBuilder.ToString();
	}
	public static string str_to_unicode(string string_1)
	{
		StringBuilder stringBuilder = new StringBuilder();
		if (!string.IsNullOrEmpty(string_1))
		{
			for (int i = 0; i < string_1.Length; i++)
			{
				stringBuilder.Append("\\u");
				stringBuilder.Append(((int)string_1[i]).ToString("x"));
			}
		}
		return stringBuilder.ToString();
	}
	public static string unicode_to_str(string content)
	{
		StringBuilder stringBuilder = new StringBuilder();
		if (!string.IsNullOrEmpty(content))
		{
			string[] array = content.Replace("\\", "").Split(new char[]
			{
				'u'
			});
			try
			{
				for (int i = 1; i < array.Length; i++)
				{
					int num = Convert.ToInt32(array[i], 16);
					stringBuilder.Append((char)num);
				}
			}
			catch (FormatException)
			{
				return Regex.Unescape(content);
			}
		}
		return stringBuilder.ToString();
	}
}
